/* jcifs smb client library in Java
 * Copyright (C) 2002  "Michael B. Allen" <jcifs at samba dot org>
 *                   "Jason Pugsley" <jcifs at samba dot org>
 *                   "skeetz" <jcifs at samba dot org>
 *                   "Eric Glass" <jcifs at samba dot org>
 *                   and Marcel, Thomas, ...
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package jcifs.http;

import jcifs.Config;
import jcifs.UniAddress;
import jcifs.smb.NtlmChallenge;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbAuthException;
import jcifs.smb.SmbSession;
import jcifs.util.Base64;
import jcifs.util.LogStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.hrm.OnLineMonitor;
import weaver.hrm.User;
import weaver.upgradetool.wscheck.Util;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * This servlet Filter can be used to negotiate password hashes with
 * MSIE clients using NTLM SSP. This is similar to <tt>Authentication:
 * BASIC</tt> but weakly encrypted and without requiring the user to re-supply
 * authentication credentials.
 * <p>
 * Read <a href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and the Network Explorer Servlet</a> for complete details.
 */

public class ADSSOFilter implements Filter {
    /**
     * jcifs自带的日志处理类实例
     */
    private static LogStream log = LogStream.getInstance();

    /**
     * 集成日志处理类
     */
    private static Logger newlog = LoggerFactory.getLogger(ADSSOFilter.class);

    /**
     * 缺少域
     */
    private String defaultDomain;

    /**
     * 域控制器
     */
    private String domainController;

    /**
     * 是否负载均衡
     */
    private boolean loadBalance;

    /**
     * 是否开启Basic认证
     */
    private boolean enableBasic;

    /**
     * 安全Basic认证
     */
    private boolean insecureBasic;

    /**
     * 认证信息
     */
    private String realm;

    /**
     * 服务器id
     */
    private String serverId;

    /**
     * 排除路径，多个用|分隔
     */
    private String excludePath;
    /**
     * servlet 上下文
     */
    private ServletContext application;


    /**
     * 初始化
     *
     * @param filterConfig
     */
    public void init(FilterConfig filterConfig) throws ServletException {

        String name;
        int level;
        this.application = filterConfig.getServletContext();
        /* Set jcifs properties we know we want; soTimeout and cachePolicy to 30min.
         */
        Config.setProperty("jcifs.smb.client.soTimeout", "1800000");
        Config.setProperty("jcifs.netbios.cachePolicy", "1200");
        //获取排除路径
        setExcludePath(Util.null2String(filterConfig.getInitParameter("excludePath")));

        /* The Filter can only work with NTLMv1 as it uses a man-in-the-middle
         * techinque that NTLMv2 specifically thwarts. A real NTLM Filter would
         * need to do a NETLOGON RPC that JCIFS will likely never implement
         * because it requires a lot of extra crypto not used by CIFS.
         */
        Config.setProperty("jcifs.smb.lmCompatibility", "0");
        Config.setProperty("jcifs.smb.client.useExtendedSecurity", "false");

        Enumeration e = filterConfig.getInitParameterNames();
        while (e.hasMoreElements()) {
            name = (String) e.nextElement();
            if (name.startsWith("jcifs.")) {
                Config.setProperty(name, filterConfig.getInitParameter(name));
            }
        }
        defaultDomain = Config.getProperty("jcifs.smb.client.domain");
        domainController = Config.getProperty("jcifs.http.domainController");
        if (domainController == null) {
            domainController = defaultDomain;
            loadBalance = Config.getBoolean("jcifs.http.loadBalance", true);
        }
        enableBasic = Boolean.valueOf(
                Config.getProperty("jcifs.http.enableBasic")).booleanValue();
        insecureBasic = Boolean.valueOf(
                Config.getProperty("jcifs.http.insecureBasic")).booleanValue();
        realm = Config.getProperty("jcifs.http.basicRealm");
        if (realm == null) realm = "jCIFS";

        if ((level = Config.getInt("jcifs.util.loglevel", -1)) != -1) {
            LogStream.setLevel(level);
        }
        if (log.level > 2) {
            try {
                Config.store(log, "JCIFS PROPERTIES");
            } catch (IOException ioe) {
            }
        }
    }

    /**
     * 销毁
     */
    public void destroy() {
    }

    /**
     * This method simply calls <tt>negotiate( req, resp, false )</tt>
     * and then <tt>chain.doFilter</tt>. You can override and call
     * negotiate manually to achive a variety of different behavior.
     *
     * @param request  请求
     * @param response 响应
     * @param chain    过滤链
     */
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        NtlmPasswordAuthentication ntlm;
        String referer = req.getHeader("referer");
//		newlog.info("###referer:"+referer);
        if (isNeedExclude(req)) {//是需要排除的路径
            chain.doFilter(req, resp);
            return;
        }
//        User olduser = (User)req.getSession(false).getAttribute("weaver_user@bean") ;
//        if(olduser!=null){ //已经登录，不需要再认证
//        	  chain.doFilter(req, resp);
//	            return;
//        }

        String logintype = getLogintype(req);
        User user = (User) req.getSession(true).getAttribute("weaver_user@bean");
        if (user == null) {
            try {
                ntlm = negotiate(req, resp, false);
                new BaseBean().writeLog("ADSSOFilter:"+(ntlm==null));
                if (ntlm== null) {
                    return;
                }
//        	if(serverId==null||"".equals(serverId)){
//				serverId = NtlmHttpServerDetector.getServerId();
//			}
                String windowsUser = "";

//        	req.getSession(false).setAttribute("weaver_login_type", "ADSSO");
//			if(NtlmHttpServerDetector.RESIN3_ID.equals(serverId)){
////				windowsUser=Util.null2String(req.getRemoteUser().trim());
//				windowsUser=Util.null2String(new NtlmHttpServletRequestForResin( req, ntlm ).getRemoteUser()).trim();
//				//chain.doFilter( new NtlmHttpServletRequestForResin( req, ntlm ), response );
//			}else{
//				windowsUser= Util.null2String(new NtlmHttpServletRequest( req, ntlm ).getRemoteUser()).trim();
//				//chain.doFilter( new NtlmHttpServletRequest( req, ntlm ), response );
//			}
                windowsUser = Util.null2String(new NtlmHttpServletRequest(req, ntlm).getRemoteUser()).trim();
               // newlog.info("###windowsUser:" + windowsUser);
                String ssologinid="";
			String[] names = windowsUser.split("\\\\");
			if(names!=null&&names.length>1)
            {
                //names[0] = Util.null2String(names[0]).trim().replaceAll("\u0000","");
                //names[1] = Util.null2String(names[1]).trim().replaceAll("\u0000","");
                ssologinid= Util.null2String(names[1]).trim().replaceAll("\u0000","");
            }else{
                ssologinid = windowsUser;
            }
        	//names[0] = Util.null2String(names[0]).trim().replaceAll("\u0000","");
        	//names[1] = Util.null2String(names[1]).trim().replaceAll("\u0000","");

                newlog.info("###ssologinid:" + ssologinid);
                if (ssologinid.contains("\\")) {
                    ssologinid = ssologinid.substring(ssologinid.indexOf("\\") + 1, ssologinid.length());
                }
                RecordSet rs = new RecordSet();

                if (!ssologinid.equals("")) {
                    rs.executeSql("select * from HrmResource where loginid ='" + ssologinid + "' and status<4 and (accounttype !=1 or accounttype is null)");
                    User user_new = null;
                    if (rs.next()) {//OA有相关人员
                   //     newlog.info("###OA有相关人员");
//					req.getSession(true).setAttribute("weaver_login_type", "OALogin");
//					req.getSession(true).setAttribute("weaver_login_type", "ADSSO");

//					String oldAccount="";
//					if(user!=null){
//						int uid = user.getUID();
//						RecordSet recordSet = new RecordSet();
//						String sql2="select * from HrmResource where id = ?";
//						recordSet.executeQuery(sql2,uid);
//						if(recordSet.next()){
//							oldAccount=recordSet.getString("loginid");
//						}
//					}
//					if(user==null||!oldAccount.equals(ssologinid)) {
                      //  newlog.info("###新用户登录");
                        if (logintype.equals("1")) {//用户登录
                            user_new = new User();
                            user_new.setUid(rs.getInt("id"));
                            user_new.setLoginid(rs.getString("loginid"));
                            user_new.setFirstname(rs.getString("firstname"));
                            user_new.setLastname(rs.getString("lastname"));
                            user_new.setAliasname(rs.getString("aliasname"));
                            user_new.setTitle(rs.getString("title"));
                            user_new.setTitlelocation(rs.getString("titlelocation"));
                            user_new.setSex(rs.getString("sex"));
                            user_new.setPwd(rs.getString("password"));
                            String languageidweaver = rs.getString("systemlanguage");
                            user_new.setLanguage(Util.getIntValue(languageidweaver, 0));

                            user_new.setTelephone(rs.getString("telephone"));
                            user_new.setMobile(rs.getString("mobile"));
                            user_new.setMobilecall(rs.getString("mobilecall"));
                            user_new.setEmail(rs.getString("email"));
                            user_new.setCountryid(rs.getString("countryid"));
                            user_new.setLocationid(rs.getString("locationid"));
                            user_new.setResourcetype(rs.getString("resourcetype"));
                            user_new.setStartdate(rs.getString("startdate"));
                            user_new.setEnddate(rs.getString("enddate"));
                            user_new.setContractdate(rs.getString("contractdate"));
                            user_new.setJobtitle(rs.getString("jobtitle"));
                            user_new.setJobgroup(rs.getString("jobgroup"));
                            user_new.setJobactivity(rs.getString("jobactivity"));
                            user_new.setJoblevel(rs.getString("joblevel"));
                            user_new.setSeclevel(rs.getString("seclevel"));
                            user_new.setUserDepartment(Util.getIntValue(rs.getString("departmentid"), 0));
                            user_new.setUserSubCompany1(Util.getIntValue(rs.getString("subcompanyid1"), 0));
                            user_new.setUserSubCompany2(Util.getIntValue(rs.getString("subcompanyid2"), 0));
                            user_new.setUserSubCompany3(Util.getIntValue(rs.getString("subcompanyid3"), 0));
                            user_new.setUserSubCompany4(Util.getIntValue(rs.getString("subcompanyid4"), 0));
                            user_new.setManagerid(rs.getString("managerid"));
                            user_new.setAssistantid(rs.getString("assistantid"));
                            user_new.setPurchaselimit(rs.getString("purchaselimit"));
                            user_new.setCurrencyid(rs.getString("currencyid"));
                            user_new.setLastlogindate(rs.getString("currentdate"));
                            user_new.setLogintype("1");
                            user_new.setAccount(rs.getString("account"));

                            user_new.setLoginip(request.getRemoteAddr());
                            req.getSession(true).setMaxInactiveInterval(60 * 60 * 24);
                            req.getSession(true).setAttribute("weaver_user@bean", user_new);
                            req.getSession(true).setAttribute("browser_isie", getisIE(req));

                            //多帐号登陆
                            if (user_new.getUID() != 1) {  //is not sysadmin
                                weaver.login.VerifyLogin VerifyLogin = new weaver.login.VerifyLogin();
                                java.util.List accounts = VerifyLogin.getAccountsById(user_new.getUID());
                                req.getSession(true).setAttribute("accounts", accounts);
                            }

                            req.getSession(true).setAttribute("moniter", new OnLineMonitor("" + user_new.getUID(), user_new.getLoginip()));
                            Util.setCookie(resp, "loginfileweaver", "/login/Login.jsp?logintype=1", 172800);
                            Util.setCookie(resp, "loginidweaver", "" + user_new.getUID(), 172800);
                            Util.setCookie(resp, "languageidweaver", languageidweaver, 172800);

                            Map logmessages = (Map) application.getAttribute("logmessages");
                            if (logmessages == null) {
                                logmessages = new HashMap();
                                logmessages.put("" + user_new.getUID(), "");
                                application.setAttribute("logmessages", logmessages);
                            }

                            req.getSession(true).setAttribute("logmessage", getLogMessage(user_new.getUID() + ""));

                            //登录日志
                            weaver.systeminfo.SysMaintenanceLog log1 = new weaver.systeminfo.SysMaintenanceLog();
                            log1.resetParameter();
                            log1.setRelatedId(rs.getInt("id"));
                            log1.setRelatedName((rs.getString("firstname") + " " + rs.getString("lastname")).trim());
                            log1.setOperateType("6");
                            log1.setOperateDesc("");
                            log1.setOperateItem("60");
                            log1.setOperateUserid(rs.getInt("id"));
                            log1.setClientAddress(request.getRemoteAddr());
                            try {
                                log1.setSysLogInfo();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }//==============
                        }
                      //  newlog.error("###登录成功：" + ssologinid);
                        String gopage=Util.null2String(req.getParameter("gopage"));
                        if(!gopage.equals("")){
                            resp.sendRedirect(gopage);
                            return;
                        }else{
                            String currentPage = req.getServletPath().toLowerCase();
                            if(currentPage.indexOf("/login/loginsso.jsp")>-1) {
                                resp.sendRedirect("/wui/main.jsp");
                                return ;
                            }
                        }
                            chain.doFilter(request, response);

                        return;
                    } else {
                        newlog.error("###OA中无此人员：loginid:" + ssologinid + "，去登录吧");
                        resp.sendRedirect("/login/OALogin.jsp");
                        return;
                    }
                } else {
                    newlog.error("###没有登录并且域中没有人员，去登录吧");
                   // resp.sendRedirect("/login/OALogin.jsp");
                    String currentPage = req.getServletPath().toLowerCase();
                    if(currentPage.indexOf("/login/loginsso.jsp")>-1) {
                        resp.sendRedirect("/login/OALogin.jsp");
                        return ;
                    }
                    chain.doFilter(request, response);
                    return;
                }
            } catch (Exception sae) {
                newlog.error("###NtlmHttpFilter :", sae);
                if (sae.getMessage().indexOf("The parameter is incorrect.") > -1) {// 跳转到OA登录页面
                    String url = "/login/LdapAttachmentDownload.jsp";
                    newlog.error("###NtlmHttpFilter : The parameter is incorrect. Response send redirect to : " + url);
                    resp.sendRedirect(url);
                    return;
                }
            }
        } else if (user != null) {
            newlog.error("###已经登录过了" + user.getUID());

            String gopage=Util.null2String(req.getParameter("gopage"));
            if(!gopage.equals("")){
                resp.sendRedirect(gopage);
                return ;
            }else{
				resp.sendRedirect("/wui/main.jsp");
                return ;
			}
            //chain.doFilter(request, response);
            //return;
        }
    }

    /**
     * Negotiate password hashes with MSIE clients using NTLM SSP
     *
     * @param req                The servlet request
     * @param resp               The servlet response
     * @param skipAuthentication If true the negotiation is only done if it is
     *                           initiated by the client (MSIE post requests after successful NTLM SSP
     *                           authentication). If false and the user has not been authenticated yet
     *                           the client will be forced to send an authentication (server sends
     *                           HttpServletResponse.SC_UNAUTHORIZED).
     * @return True if the negotiation is complete, otherwise false
     */
    protected NtlmPasswordAuthentication negotiate(HttpServletRequest req,
                                                   HttpServletResponse resp,
                                                   boolean skipAuthentication) throws IOException, ServletException {
        UniAddress dc;
        String msg;
        NtlmPasswordAuthentication ntlm = null;
        msg = req.getHeader("Authorization");
        boolean offerBasic = enableBasic && (insecureBasic || req.isSecure());

        if (msg != null && (msg.startsWith("NTLM ") ||
                (offerBasic && msg.startsWith("Basic ")))) {
            if (msg.startsWith("NTLM ")) {
                HttpSession ssn = req.getSession();
                byte[] challenge;

                if (loadBalance) {
                    NtlmChallenge chal = (NtlmChallenge) ssn.getAttribute("NtlmHttpChal");
                    if (chal == null) {
                        chal = SmbSession.getChallengeForDomain();
                        ssn.setAttribute("NtlmHttpChal", chal);
                    }
                    dc = chal.dc;
                    challenge = chal.challenge;
                } else {
                    dc = UniAddress.getByName(domainController, true);
                    challenge = SmbSession.getChallenge(dc);
                }

                if ((ntlm = NtlmSsp.authenticate(req, resp, challenge)) == null) {
                    return null;
                }
                /* negotiation complete, remove the challenge object */
                ssn.removeAttribute("NtlmHttpChal");
            } else {
                String auth = new String(Base64.decode(msg.substring(6)),
                        "US-ASCII");
                int index = auth.indexOf(':');
                String user = (index != -1) ? auth.substring(0, index) : auth;
                String password = (index != -1) ? auth.substring(index + 1) :
                        "";
                index = user.indexOf('\\');
                if (index == -1) index = user.indexOf('/');
                String domain = (index != -1) ? user.substring(0, index) :
                        defaultDomain;
                user = (index != -1) ? user.substring(index + 1) : user;
                ntlm = new NtlmPasswordAuthentication(domain, user, password);
                dc = UniAddress.getByName(domainController, true);
            }
            try {

                SmbSession.logon(dc, ntlm);

                if (log.level > 2) {
                    log.println("NtlmHttpFilter: " + ntlm +
                            " successfully authenticated against " + dc);
                }
            } catch (SmbAuthException sae) {
                if (log.level > 1) {
                    log.println("NtlmHttpFilter: " + ntlm.getName() +
                            ": 0x" + jcifs.util.Hexdump.toHexString(sae.getNtStatus(), 8) +
                            ": " + sae);
                }
                if (sae.getNtStatus() == sae.NT_STATUS_ACCESS_VIOLATION) {
                    /* Server challenge no longer valid for
                     * externally supplied password hashes.
                     */
                    HttpSession ssn = req.getSession(false);
                    if (ssn != null) {
                        ssn.removeAttribute("NtlmHttpAuth");
                    }
                }
                resp.setHeader("WWW-Authenticate", "NTLM");
                if (offerBasic) {
                    resp.addHeader("WWW-Authenticate", "Basic realm=\"" +
                            realm + "\"");
                }
                resp.getOutputStream().print("<script language=javascript>window.location.href='/login/OALogin.jsp?logintype=1&message=60';</script>");
                //resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
                //resp.setContentLength(0); /* Marcel Feb-15-2005 */
                //resp.flushBuffer();
                return null;
            }
            req.getSession().setAttribute("NtlmHttpAuth", ntlm);
        } else {
            if (!skipAuthentication) {
                HttpSession ssn = req.getSession(false);
                if (ssn == null || (ntlm = (NtlmPasswordAuthentication)
                        ssn.getAttribute("NtlmHttpAuth")) == null) {
                    resp.setHeader("WWW-Authenticate", "NTLM");
                    if (offerBasic) {
                        resp.addHeader("WWW-Authenticate", "Basic realm=\"" +
                                realm + "\"");
                    }
                    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                    resp.setContentLength(0);
                    resp.flushBuffer();
                    return null;
                }
            }
        }

        return ntlm;
    }

    /**
     * Added by cgross to work with weblogic 6.1.
     *
     * @param f 过滤器配置
     */
    public void setFilterConfig(FilterConfig f) {
        try {
            init(f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取过滤器配置
     *
     * @return 过滤器配置
     */
    public FilterConfig getFilterConfig() {
        return null;
    }

    /**
     * @param excludePath
     */
    public final void setExcludePath(final String excludePath) {
        this.excludePath = excludePath;
    }


    /**
     * 是否排除路径
     *
     * @param
     * @return
     */
    private boolean isNeedExclude(HttpServletRequest request) {
        boolean result = false;
        //当前页面
        String currentPage = request.getServletPath();
        //newlog.info("###currentPage:" + currentPage);
        //根据配置的页面判断前面页面是否在排除页面中
        String excludes[] = this.excludePath.replace("\r", "").replace("\n", "").replaceAll(" ", "").replace("\t", "").split("[|]");
        for (int i = 0; i < excludes.length; i++) {
            //newlog.info("###excludes:" + excludes[i]);
            if(excludes[i]==null||excludes[i].equals("")) continue;
            if (currentPage.indexOf(excludes[i]) == 0) {
                String exclude = request.getHeader("exclude");
                if ("workflowtodoc".equals(exclude)) {
                    request.getSession(true).setAttribute("weaver_login_type", "OALogin");
                }
                result = true;
                break;
            }
        }
        //判断当前页面是否是指定的sysadmin登录页面
        if (currentPage.equalsIgnoreCase("/login/OALogin.jsp")) {
//				request.getSession(true).setAttribute("weaver_login_type","ADSSO");
            result = true;
        }
        //判断来源页面是否是指定的sysadmin登录页面
        String referer = request.getHeader("referer");
//			newlog.info("###referer:"+referer);
        if (referer != null) {
            if (referer.indexOf("/login/OALogin.jsp") > -1) {
                result = true;
            }
        }

        if (referer != null) {
            if (referer.indexOf("/wui/engine.html") > -1 && currentPage.indexOf("/wui/index.html") > -1) {
                result = true;
            }
        }

        //判断是否是原OA的登录方式或者emessage登录
        String weaver_login_type = (String) request.getSession(true).getAttribute("weaver_login_type");
        if (weaver_login_type != null) {
            if (weaver_login_type.equals("emessage") || weaver_login_type.equals("OALogin")) {
                result = true;
            }
        }
        //判断当前页面是否是OA登录页面
        if (currentPage.equalsIgnoreCase("/login/Login.jsp")) {
            request.getSession(true).removeAttribute("weaver_login_type");
            result = false;
        }
//			String queryString = request.getQueryString();
        //277481,lv,[90]集成中心－解决代码质量问题修复--不允许使用 System.out.println()
        //System.out.println("currentPage="+currentPage+(queryString==null || queryString.equals("") ? "":"?"+queryString)+", referer="+referer+", weaver_login_type="+weaver_login_type+", result="+result);
        newlog.info("是否排除路径:" + result);
        return result;
    }

    private String getLogMessage(String uid) {
        String message = "";
        RecordSet rs = new RecordSet();
        String sqltmp = "";
        if (rs.getDBType().equals("oracle")) {
            sqltmp = "select * from (select * from SysMaintenanceLog where relatedid = " + uid + " and operatetype='6' and operateitem='60' order by id desc ) where rownum=1 ";
        } else if (rs.getDBType().equals("db2")) {
            sqltmp = "select * from SysMaintenanceLog where relatedid = " + uid + " and operatetype='6' and operateitem='60' order by id desc fetch first 1 rows only ";
        } else {
            sqltmp = "select top 1 * from SysMaintenanceLog where relatedid = " + uid + " and operatetype='6' and operateitem='60' order by id desc";
        }

        rs.executeSql(sqltmp);
        if (rs.next()) {
            message = rs.getString("clientaddress") + " " + rs.getString("operatedate") + " " + rs.getString("operatetime");
        }

        return message;
    }

    private String getLogintype(HttpServletRequest request) {
        String logintype = Util.null2String(request.getParameter("logintype"));
        String userLogintype = "";
        User user = (User) request.getSession(true).getAttribute("weaver_user@bean");
        if (user != null) {
            userLogintype = Util.null2String(user.getLogintype());
            logintype = userLogintype;
        }

        if (logintype.equals("")) {
            logintype = "1";
        }

        return logintype;
    }

    // 判断浏览器是否为IE
    private String getisIE(HttpServletRequest request) {
        String isIE = "true";
        String agent = request.getHeader("User-Agent").toLowerCase();
        if (agent.indexOf("rv:11") == -1 && agent.indexOf("msie") == -1) {
            isIE = "false";
        }
        if (agent.indexOf("rv:11") > -1 || agent.indexOf("msie") > -1) {
            isIE = "true";
        }
        return isIE;
    }

}

